﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Dynamic;

//引入dotNetDR_OAuth2组件命名空间
using dotNetDR_OAuth2;
using dotNetDR_OAuth2.AccessToken;

namespace dotNetDR_OAuth2.Sample.MVC.Controllers
{
    public class HomeController : Controller
    {
        //获取新浪、腾讯的IAuthorizationCodeBase接口实例
        private IAuthorizationCodeBase sina = Uf.C(CtorAT.Sina);
        private IAuthorizationCodeBase tencent = Uf.C(CtorAT.Tencent);

        public ActionResult Index()
        {
            dynamic model = new ExpandoObject();

            //生成主机头例如：http://www.yourhost.com:8081 (注：默认80端口则不会显示:80)
            var hostPath = AccessTokenToolkit.GenerateHostPath(Request.Url);

            //定义授权成功后返回的url地址
            var sinaRedirectUrl = hostPath + Url.Action("Index", "Sina");
            var tencentRedirectUrl = hostPath + Url.Action("Index", "Tencent");

            //设置超级链接
            model.SinaLink = sina.GenerateCodeUrl(sinaRedirectUrl);
            model.TencentLink = tencent.GenerateCodeUrl(tencentRedirectUrl);

            Session.Remove("accessToken");

            return View(model);
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
